#pragma once
#include"Poller.h"
#include <poll.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <string.h>  // memset
#include <string>
namespace wjc {

    /// IO Multiplexing with epoll(4).
///
    class EPollPoller : public Poller
    {
    public:
        EPollPoller(Core* core);
        ~EPollPoller() override;

        Timestamp poll(int timeoutMs, ChannelList* activeChannels) override;
        void updateChannel(Channel* channel) override;
        void removeChannel(Channel* channel) override;

    private:
        static const int kInitEventListSize = 16;

        static const char* operationToString(int op);

        void fillActiveChannels(int numEvents,
            ChannelList* activeChannels) const;
        void update(int operation, Channel* channel);

        typedef std::vector<struct epoll_event> EventList;

        int epollfd_;
        EventList events_;
    };

}